package com.wx.lambda.stream;

import java.util.stream.Stream;

/**
 * Stream 操作
 * @author wangxun
 * @version 1.0
 * @description: Stream 操作
 * @date 2020/11/26 11:14 上午
 */
public class MyStream {
    private Stream<String> stream;

    public MyStream(Stream stream) {
        this.stream = stream;
    }

    /**
     * 遍历
     */
    public void forEach(){
        stream.forEach(System.out::println);
    }

    /**
     * 过滤
     */
    public void filter(){
        stream.filter(str->str.length()>3).forEach(System.out::println);
    }

    /**
     * 去重
     */
    public void distinct(){
        stream.distinct().forEach(System.out::println);
    }

    /**
     * 排序
     */
    public void sorted(){
        stream.sorted((s1,s2)->s1.length()-s2.length()).forEach(System.out::println);
    }

    /**
     * 对每个元素进行操作
     */
    public void map(){
        stream.map(str->str.toLowerCase()).forEach(System.out::println);
    }
}
